<template>
  <div class="app-container">
    <el-form :inline="true" label-width="">
      <el-form-item label="手机">
        <el-input
          v-model="queryParams.mobile"
          placeholder="手机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="queryParams.type" placeholder="类型" clearable size="small">
          <el-option label="所有类型" value=""/>
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="发送时间">
        <el-date-picker
          v-model="startTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!--<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:post:add']">新增</el-button>-->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="postList">
     <!-- <el-table-column label="用户编号" align="center" prop="idNo"/>
      <el-table-column label="用户昵称" align="center" prop="nickname"/>-->
      <el-table-column label="手机号码" align="center" prop="mobile"/>
      <el-table-column label="类型" align="center" prop="type" :formatter="statusFormat"/>
      <el-table-column label="发送状态" align="center" prop="code"/>
      <el-table-column label="发送时间" align="center" prop="datetime" >
        <template slot-scope="scope">
          <span>{{ dateFormat(scope.row.datetime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
  import {list} from "@/api/main/sms/sms";

  export default {
    data() {
      return {
        startTime:'',
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        //open: false,
        // 状态数据字典
        statusOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          mobile: undefined,
          nickname: undefined,
          status: undefined,
          startTime:undefined,
          endTime:undefined
        },
      };
    },
    created() {
      this.getList();
      // this.statusOptions=[{dictLabel:'创业中',dictValue:'1'},{dictLabel:'已关闭',dictValue:'0'}];
      this.getDicts("sms_status_type").then(response => {
        this.statusOptions = response.data;
      });
    },
    methods: {
      /** 查询岗位列表 */
      getList() {
        this.loading = true;
        list(this.queryParams).then(response => {
          this.postList = response.rows;
          for(let i=0;i<this.postList.length;i++){
            let  json=this.postList[i].back;
            let obj = JSON.parse(json);
            this.postList[i].code=obj.code==='0'?'成功':'失败';
          }

          this.total = response.total;
          this.loading = false;
        });
      },
      // 岗位状态字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.type);
      },
      realNameFormat(row,column){
        return row.realName?row.realName:'-';
      },

      handleQuery() {
        if(this.startTime){
          this.queryParams.startTime= this.startTime[0]+" 00:00:00";
          this.queryParams.endTime=this.startTime[1]+" 11:59:59";
        }else{
          this.queryParams.startTime=null;
          this.queryParams.endTime=null;
        }
        this.queryParams.pageNum = 1;
        this.getList();
      }
    }
  };
</script>
